package o;

import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean.e;
import java.util.concurrent.ConcurrentHashMap;

public class cwg {
    private static final cwg ˋ = new cwg();
    private ConcurrentHashMap<String, a> ˎ = new ConcurrentHashMap();

    static class a {
        long ˋ;
        int ˏ;
        String ॱ;

        a() {
        }
    }

    private cwg() {
    }

    public static cwg ˎ() {
        return ˋ;
    }

    public ResponseBean ˊ(String str, String str2) {
        int i = 0;
        try {
            i = Integer.parseInt(str2);
        } catch (NumberFormatException e) {
            cvp.ˎ.ˋ("ServerAccessController", "parseInt 'retryAfter' exception : " + e.toString());
        }
        if (i <= 0 || this.ˎ.containsKey(str)) {
            return ˎ(str, 1);
        }
        a aVar = new a();
        aVar.ॱ = str;
        aVar.ˏ = i * 1000;
        aVar.ˋ = System.currentTimeMillis();
        this.ˎ.put(str, aVar);
        return ˎ(str, ResponseBean.SERVER_DELAY_RETRY);
    }

    public ResponseBean ˋ(String str) {
        a aVar = (a) this.ˎ.get(str);
        if (aVar != null) {
            long currentTimeMillis = System.currentTimeMillis() - aVar.ˋ;
            if (currentTimeMillis < ((long) aVar.ˏ)) {
                cvp.ˎ.ˋ("ServerAccessController", "The method " + str + " can access the server after " + (((long) aVar.ˏ) - currentTimeMillis));
                return ˎ(str, ResponseBean.SERVER_DELAY_RETRY);
            }
            this.ˎ.remove(str, aVar);
        }
        return null;
    }

    private ResponseBean ˎ(String str, int i) {
        ResponseBean ˊ;
        Throwable e;
        Throwable th;
        try {
            ˊ = cvr.ˊ(str);
            try {
                ˊ.setRtnCode_(0);
                ˊ.setResponseCode(i);
                ˊ.setErrCause(e.SERVER_FLOW_CONTROL);
            } catch (InstantiationException e2) {
                e = e2;
                cvp.ˎ.ˊ("ServerAccessController", "getDelayRetryResponse, create response error, method:" + str, e);
                return ˊ;
            } catch (IllegalAccessException e3) {
                e = e3;
                cvp.ˎ.ˊ("ServerAccessController", "getDelayRetryResponse, create response error, method:" + str, e);
                return ˊ;
            }
        } catch (Throwable e4) {
            th = e4;
            ˊ = null;
            e = th;
            cvp.ˎ.ˊ("ServerAccessController", "getDelayRetryResponse, create response error, method:" + str, e);
            return ˊ;
        } catch (Throwable e42) {
            th = e42;
            ˊ = null;
            e = th;
            cvp.ˎ.ˊ("ServerAccessController", "getDelayRetryResponse, create response error, method:" + str, e);
            return ˊ;
        }
        return ˊ;
    }
}
